More Than 15,000 How-to Solutions Terms of Use
 
Google Web eHow.com
Home > Computers & Home Electronics Center > World Wide Web
 

How to Password-Protect a Web Page

Password protection keeps only the users you want on your page. If you know JavaScript or even plain old HTML, you can use password protection.
 
Placing a Link from an Unprotected Page to a Protected Page
 
Steps:
1.  Open the unprotected page in a basic text editor. Place the cursor where the link will appear.
 
2.  Type the following, substituting your own text or graphic: Click here to access the password protected page.
 
 
Tips:
Users must click on a link to access a page unless the first page of a site is protected. If the main page is the password protected page, start at Section 2.
 
For the purposes of this section, the destination of the link, a script file, is called "password.html".
 
 
Creating a Script for the Password Page
 
Steps:
1.  Open a basic text editing program. Begin by typing the opening tags: <html><head>
 
2.  Type the title of your page and close the title with a tag: <title>Protected Page: Please enter password</title>
 
3.  Type the following:  <script language="Javascript"> This command tells the browser a script is about to begin.
 
4.  Press the Enter key and type the following: //prompt. Press the Enter key again.
 
5.  Enter the prompt by typing the following: var password = prompt("Enter in the password""");  There are three double-quotation marks after the word "password" and a semicolon after the last parentheses.
 
6.  Type the following, replacing "pass" with the word or numbers the password will be: if (password == "pass")
 
7.  Now type the following, replacing "correct.html" with the name of the page the correct user is directed to: {location = "correct.html"} This tells the browser to send the user who enters the correct password to this page.
 
8.  Send users who type the incorrect password to an error page by typing the following, replacing "error.html" with the error page you have created: else {location = "error.html"}
 
9.  End the script by typing the following: //--></script>
 
10.  Close the scripted section of the page by typing the follow: </head>.
 
11.  Add a body section for browsers that do not read JavaScript: <body>This page is designed for viewing by Netscape 2.0, Internet Explorer 3.0 or above. Please upgrade your browser and return soon!</body>
 
12.  Close the Web page by typing: </html> Save the page (for this example, save it as "password.html").
 
 
Tips:
Users who enter the correct password are taken straight to the page; users who enter the incorrect password are sent to an error page. You create the error page, called "error.html" here, in the next section.
 
Be sure to enter all commands as shown. JavaScript will not work if the command isn't exactly right.
 
 
Creating the Error Page
 
Steps:
1.  Open a basic text editing program. Begin by typing the opening tags: <html><head><title>
 
2.  Title the page "Error" or "Wrong Password": <title>Sorry ' Wrong Password!</title></head>
 
3.  Type the error message the viewer will see, such as: <body> <h1>I'm sorry, the password you typed is incorrect.
 
4.  Give the user an opportunity to re-enter the password: Please click here to try again. This allows the user the opportunity to return to the password script.
 
5.  Allow the user to back out: <p>Otherwise, click here to return to the main page. </h1>("here.html" indicates the name of the page that links to the protected page)
 
6.  Close the page by typing the closing tags: </body></html>
 
 
Tips:
Format this page to resemble your other pages, so viewers don't get lost.
 
 
Testing the Password Script
 
Steps:
1.  Open a Web browser. Select Open from the File menu, locate the page that links to the password-protected page, and click Open to view it.
 
2.  Click on the link to the password-protected page.
 
3.  You will be prompted for the password. Make sure you enter it correctly; passwords are case-sensitive.
 
4.  Gauge the results. If it does not work, go back and double-check that you entered the script correctly.
 
 
Tips:
Try typing both the correct and incorrect passwords so you will see what your visitors see.
 
 
Warnings:
Do not link back to the password file (password.html). If the person does not know the password, they will be endlessly looped and cannot get out of the script.
 
Finding More Complex Password-Protection Scripts
 
Steps:
1.  Visit pages that offer free JavaScripts and do a search for "password". Many of these scripts are just cut and paste, with minimal changes.
 
2.  Protect extremely sensitive information by hiring a Web developer (or your ISP) to create a customized password script for you. These scripts are extremely sensitive and very difficult for hackers.
 
3.  Contact your Internet Service Provider and ask if they provide password protection services. This entails setting aside a portion of the server for your pages, so some ISPs may charge extra.
 
4.  If you use a free script, add a courtesy button or reference to the provider on your page.
 
5.  You may need to get permission before using JavaScripts from another Web site. When in doubt, ASK!
 
6.  Not all browsers support scripts. Be sure to follow directions for providing alternates to scripts on your Web page.
 
 
 
Please Share Your Tips with Us
E-mail this page to a friend

More Resources:
Related eHows:
Learn About Java
Learn About JavaScript
Create Your First Web Site
Add a Link to a Web Page
Learn HTML
Things You'll Need:
Project Details:
Skill Advisory: Easy

 
Related eHows:
Learn About Java
Learn About JavaScript
Create Your First Web Site
Add a Link to a Web Page
Learn HTML
 


 

Check Out 15,000 More How-To Solutions in eHow's Centers
Automotive Careers & Education Computers & Home Electronics Family & Relationships Finance & Business
Food & Entertaining Health Hobbies & Games Holidays & Traditions Home & Garden
Personal Care & Style Pets Sports & Fitness Travel

Google Web eHow.com

Home  |   Site Map  
Register with eHow  |   About Us  |   Privacy  |   Terms of Use  |   eHow Book  |   Link to eHow  |   Free Offers   |  Login

© 1999-2004 eHow, Inc. How things get done.
Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy.